/**
 * @author LANG
 * Copyright 2009, QSC.
 * All rights reserved.
 */
float4x4 worldViewProjection : WorldViewProjection;

sampler tex1;
sampler positionTex;

float power;
	  
struct VertexShaderInput {
	float4 position : POSITION;
	float2 tex : TEXCOORD0;  // Texture coordinates
};
 
VertexShaderInput vertexShaderFunction(VertexShaderInput input) {
	VertexShaderInput output;

	output.position = mul(input.position, worldViewProjection);
		
	output.tex = input.tex;
	return output;
}
  
float4 pixelShaderFunction(VertexShaderInput input): COLOR {
	input.tex.y = 1 - input.tex.y;
    
    float2 samples[12] = {
      -0.326212, -0.405805,
      -0.840144, -0.073580,
      -0.695914,  0.457137,
      -0.203345,  0.620716,
       0.962340, -0.194983,
       0.473434, -0.480026,
       0.519456,  0.767022,
       0.185461, -0.893124,
       0.507431,  0.064425,
       0.896420,  0.412458,
      -0.321940, -0.932615,
      -0.791559, -0.597705,
   };
   
   float2 samples2[4] = {
   	 -2, 0,
   	 1, 0,
   	 0, -2,
   	 0, 2
   };
   
   float edge = 0;
   for(int i = 0; i < 4; i++){
   		if(tex2D(positionTex, input.tex).z - tex2D(positionTex, input.tex + 0.001*power*samples2[i]).z > 0.005)
   		{
   			edge = 1;
   		}
   }
	
   float4 sum = tex2D(tex1, input.tex);
   
   if(edge == 1){
   		return sum;
   }
   
   for (int i = 0; i < 12; i++){
      sum += tex2D(tex1, input.tex + 0.001 * power * samples[i]);
   }
	return sum/13;
}
  
// #o3d VertexShaderEntryPoint vertexShaderFunction
// #o3d PixelShaderEntryPoint pixelShaderFunction
// #o3d MatrixLoadOrder RowMajor